/**********************************************************
 * set data to the clipboard
***********************************************************/
function setClipboard(CopiedText) {
	if (window.clipboardData) {   //for IE
		return (window.clipboardData.setData("Text", CopiedText));
	} else {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
				if(!clip) {
					return false;
				}
 
				var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
				if(!trans) {
					return false;
				}
				trans.addDataFlavor("text/unicode");
				var str = new Object();
				var len = new Object();
				var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
				var copytext = CopiedText;
				str.data = copytext;
				trans.setTransferData("text/unicode", str, copytext.length * 2);
				var clipid = Components.interfaces.nsIClipboard;
				if(!clip) {
					return false;
				}
				clip.setData(trans, null, clipid.kGlobalClipboard);
				return true;
			} catch(e) {
				alert("Your firefox security settings have disabled the clipboard operations, to change these settings, please see the usr manual file.");
				return false;
			}
		}
	}
	return false;
};

/**********************************************************
 * get data from the clipboard
***********************************************************/
function getClipboard() {
	if (window.clipboardData) {
		return (window.clipboardData.getData("text"));
	} else {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
				if(!clip) {
					return false;
				}
				var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
				if(!trans) {
					return false;
				}
				trans.addDataFlavor("text/unicode");
				clip.getData(trans, clip.kGlobalClipboard);
				var str = new Object();
				var len = new Object();
				trans.getTransferData("text/unicode", str, len);
			} catch (e) {
				alert("Your firefox security settings have disabled the clipboard operations, to change these settings, please see the usr manual file.");
				return null;
			} 
			if(str) {
				if (Components.interfaces.nsISupportsWString) {
					str = str.value.QueryInterface(Components.interfaces.nsISupportsWString);
				} else {
					if (Components.interfaces.nsISupportsString) {
						str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
					} else {
						str = null;
					}
				}
			}
 
			if(str) {
				return (str.data.substring(0, len.value / 2));
			}
		}	
	}
	return null;
};